package scientistengineer.blogspot.affrpor;


import java.text.Format.Field;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

//sound IDs, constants and variables for the sounds



public class Greetings extends Activity {
	
	private PlayTextListAdapter adapter;
	private ListView listAdapter;
	private int offset_map=0;
	
	//sounds IDs, constants and variables for the sounds
	
	private static final int SOUND_PRIORITY =1;
	private static final int SOUND_QUALITY = 100;
	private static final int MAX_STREAMS = 11;
	
	private SoundPool soundPool;
	private int volume;
	private Map<Integer, Integer> soundMap;
	
	PlayTextRow [] row_data;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.greetings_menu);
		
		row_data = new PlayTextRow[]
				{
					new PlayTextRow(R.drawable.play_br, "Ola", "Dagse",  R.drawable.play_sa),
					new PlayTextRow(R.drawable.play_br, "Oi", "Hi",  R.drawable.play_sa),
					new PlayTextRow(R.drawable.play_br, "Tchau", "baai",  R.drawable.play_sa),
					new PlayTextRow(R.drawable.play_br, "Ate mais tarde", "Sien jou later",  R.drawable.play_sa),
					new PlayTextRow(R.drawable.play_br, "Ate logo", "Sien jou gou weer",  R.drawable.play_sa),
					new PlayTextRow(R.drawable.play_br, "Ate amanha", "Sien jou more",  R.drawable.play_sa),
				};
		
		adapter = new PlayTextListAdapter(this, R.layout.atom_play_translation, row_data);	
		listAdapter = (ListView) findViewById(R.id.greetingsListView);		
		listAdapter.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub			
			}	
		});
		
		listAdapter.setAdapter(adapter);			
		//seting the sounds effect 
		soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);	
		
		//create Map of sounds and pre-load sounds
		soundMap = new HashMap<Integer, Integer>();
		soundMap.put(0, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_dagse", "raw", this.getPackageName()), 1));
		soundMap.put(1, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_hi", "raw", this.getPackageName()), 1));
		soundMap.put(2, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_bye", "raw", this.getPackageName()), 1));
		soundMap.put(3, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_sien_jou_later", "raw", this.getPackageName()), 1));
		soundMap.put(4, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_sien_jou_gou_weer", "raw", this.getPackageName()), 1));
		soundMap.put(5, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_sien_jou_more", "raw", this.getPackageName()), 1));
		soundMap.put(6, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_ola", "raw", this.getPackageName()), 1));
		soundMap.put(7, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_oi", "raw", this.getPackageName()), 1));
		soundMap.put(8, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_tchau", "raw", this.getPackageName()), 1));
		soundMap.put(9, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_ate_mais_tarde", "raw", this.getPackageName()), 1));
		soundMap.put(10, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_ate_logo", "raw", this.getPackageName()), 1));
		soundMap.put(11, soundPool.load(this, this.getResources().getIdentifier("raw/beginner_greetings_ate_amanha", "raw", this.getPackageName()), 1));
		/*MediaPlayer mPlayer2;
		mPlayer2= MediaPlayer.create(this, R.raw.dagse);
	    mPlayer2.start();*/
		
		this.adapter.setOnPortClickListener(new OnClickListener() {
		    @Override
		    public void onClick(View v) {
		    	
		    	final int position = listAdapter.getPositionForView(v);
		        
		        switch(position+offset_map)
				{
				case 6:
				case 7:
				case 8:
				case 9:
				case 10:
				case 11:
					soundPool.play(soundMap.get(position+offset_map), 1, 1, 1, 0, 1f);
					break;			
				} 
		    }
		});
		
		this.adapter.setOnAffrClickListener(new OnClickListener() {
		    @Override
		    public void onClick(View v) {
		    	
		    	final int position = listAdapter.getPositionForView(v);
		        
		        switch(position)
				{
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
					soundPool.play(soundMap.get(position), 1, 1, 1, 0, 1f);
					break;		
				}        
		    }
		});	
		offset_map = 6;
	}
}
